using System;
using System.Collections.Generic;
using System.Text;
using Barrage.Global;

namespace Spacedash.Logic.RaceStates
{
    /// <summary>
    /// A race in this state has all the ships in the starting grid, waiting for the race to start.
    /// After some time, the state will change to Racing and the race will start.
    /// </summary>
    public class StartingRaceState:RaceState
    {
        /// <summary>
        /// \internal State identifier
        /// </summary>
        public override RaceStateList State
        {
            get { return RaceStateList.Starting; }
        }
        const float START_TIMER = 5f;
        float startTime;
        /// <summary>
        /// Remaining time until race start
        /// </summary>
        public float Remaining { get { return START_TIMER - (Timer.DefaultTimer.TotalTimeSeconds - startTime); } }

        /// <summary>
        /// Constructor. Inits the timer
        /// </summary>
        /// <param name="race">Race instance</param>
        public StartingRaceState(Race race):base(race)
        {
            startTime = Timer.DefaultTimer.TotalTimeSeconds;
        }
        /// <summary>
        /// \internal Changes the race state when the time expires
        /// </summary>
        public override void Update()
        {
            if (Remaining<=0)
                race.State = new RacingRaceState(race);
        }
    }
}
